﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "MVC/graphicsview.h"
#include "MVC/graphicsscene.h"
#include <QDebug>
#include <QKeyEvent>
#include "Help/aboutdialog.h"
#include "Help/instrucdialog.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//    ui->menuBar->hide();
    ui->mainToolBar->hide();
//    setWindowFlags (Qt::CustomizeWindowHint);
//    setWindowFlags (Qt::FramelessWindowHint);
    view = new GraphicsView();
//    scene = new GraphicsScene();
//    view->setScene(scene);
    view->hide();

    this->setCentralWidget(view);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_action_quit_triggered()
{
    this->close();
}

void MainWindow::on_action_start_triggered()
{
    view->show();
    view->setFocus();
    view->game_start();
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    view->close();
    QMainWindow::closeEvent(event);
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Escape){
        ui->menuBar->show();
        ui->statusBar->show();
        this->showNormal();
    }

    if((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && event->modifiers() == Qt::AltModifier){
        if(this->isFullScreen()){
            ui->menuBar->show();
            ui->statusBar->show();
            this->showNormal();
        }
        else{
            ui->menuBar->hide();
            ui->statusBar->hide();
            this->showFullScreen();
        }
    }

    QMainWindow::keyPressEvent(event);
}

void MainWindow::on_action_fullScreen_triggered()
{
    ui->menuBar->hide();
    ui->statusBar->hide();
    this->showFullScreen();
}

void MainWindow::on_action_instructions_triggered()
{
    InstrucDialog dlg(this);
    dlg.exec();
}

void MainWindow::on_action_about_triggered()
{
    AboutDialog dlg;
    dlg.exec();
}
